﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.UserCash
{
    public partial class MoneyCardCash : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region 提交
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string moneycardno = txtMoneyCardNo.Text.Trim();
            if (string.IsNullOrEmpty(moneycardno))
            {
                Tools.Alert("请输入友赢券号码");
                return;
            }
            else
            {
                //判断号码的有效性
                MoneyCardHelper mchelper = new MoneyCardHelper();
                Criteria c = new Criteria();
                c.Add(CriteriaType.Equals, "MoneyCardNo", moneycardno);
                c.Add(CriteriaType.Equals, "Flag", 0);
                c.Add(CriteriaType.Equals, "Status", 0);
                List<MoneyCard> mclist = mchelper.QueryMoneyCardBySearch(c, null);
                if (mclist != null && mclist.Count > 0)//存在
                {
                    Users uinfo=UserBase.GetCurrentUser();
                    MoneyCard mcinfo = mclist[0];
                    mcinfo.Status = 1;
                    mcinfo.UsersID = uinfo.ID;
                    mcinfo.UsedDate = System.DateTime.Now;
                    mchelper.EditMoneyCard(mcinfo);

                    int money = mcinfo.Money;
                    //当前用户增加相应的金额
                    CashFlow cfinfo = new CashFlow();
                    CashFlowHelper cfhelper = new CashFlowHelper();
                    cfinfo.UsersID = uinfo.ID;
                    cfinfo.Money = money;
                    cfinfo.Type = 1;
                    cfinfo.Description = "友赢券充值";
                    cfhelper.AddCashFlow(cfinfo);

                    Tools.AlertAndRedirect("您成功充值友赢豆" + money + "个", "CashFlowList.aspx");
                    return;
                }
                else//不存在
                {
                    Tools.Alert("友赢券号码无效，请重新输入");
                    return;
                }
            }
        }
        #endregion
    }
}